package com.wilson.integration.lease.app.service.impl;

import com.wilson.integration.lease.common.entity.ApartmentInfo;
import com.wilson.integration.lease.common.entity.FacilityInfo;
import com.wilson.integration.lease.common.entity.LabelInfo;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentDetailVO;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentItemVO;
import com.wilson.integration.lease.common.entity.vo.graph.GraphVO;
import com.wilson.integration.lease.common.enums.ItemType;
import com.wilson.integration.lease.common.mapper.*;
import com.wilson.integration.lease.app.service.ApartmentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wilson
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo> implements ApartmentInfoService {

    @Resource
    private ApartmentInfoMapper apartmentInfoMapper;

    @Resource
    private LabelInfoMapper labelInfoMapper;

    @Resource
    private GraphInfoMapper graphInfoMapper;

    @Resource
    private RoomInfoMapper roomInfoMapper;

    @Resource
    private FacilityInfoMapper facilityInfoMapper;


    @Override
    public ApartmentItemVO selectApartmentItemVOById(Long apartmentId) {
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);

        List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(apartmentId);

        List<GraphVO> graphVOList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, apartmentId);

        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(apartmentId);

        ApartmentItemVO apartmentItemVO = new ApartmentItemVO();
        BeanUtils.copyProperties(apartmentInfo, apartmentItemVO);

        apartmentItemVO.setGraphVOList(graphVOList);
        apartmentItemVO.setLabelInfoList(labelInfoList);
        apartmentItemVO.setMinRent(minRent);
        return apartmentItemVO;
    }

    @Override
    public ApartmentDetailVO getApartmentDetailById(Long id) {
        // 1.查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);
        // 2.查询图片信息
        List<GraphVO> graphVOList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, id);
        // 3.查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(id);
        // 4.查询配套信息
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectListByApartmentId(id);
        // 5.查询最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);

        ApartmentDetailVO apartmentDetailVO = new ApartmentDetailVO();

        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVO);
        apartmentDetailVO.setGraphVOList(graphVOList);
        apartmentDetailVO.setLabelInfoList(labelInfoList);
        apartmentDetailVO.setFacilityInfoList(facilityInfoList);
        apartmentDetailVO.setMinRent(minRent);
        return apartmentDetailVO;
    }
}




